<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../javascript/lib/jquery.js"></script>
</head>
<body>

<div id="list"></div>
<script>

    (function(){

        let arrayLike = {
            '0': 'a',
            '1': 'b',
            '2': 'c',
            length: 3
        };

        // ES5的写法
        var arr1 = [].slice.call(arrayLike); // ['a', 'b', 'c']

        // ES6的写法
        let arr2 = Array.from(arrayLike); // ['a', 'b', 'c']


        //Array.from还可以接受第二个参数，作用类似于数组的map方法--------------
        Array.from(arrayLike, x => x * x);
        // 等同于
        Array.from(arrayLike).map(x => x * x);

        Array.from([1, 2, 3], (x) => x * x)

        //遍历节点----------------------------------------------

        let spans = document.querySelectorAll('span.name');

        let names1 = Array.prototype.map.call(spans, s => s.textContent);

        let names2 = Array.from(spans, s => s.textContent)

        //遍历类型------------------------------
        function typesOf () {
            return Array.from(arguments, value => typeof value)
        }
        typesOf(null, [], NaN)
        // ['object', 'object', 'number']

    });

    (function(){

        Array.of(3, 11, 8) // [3,11,8]
        Array.of(3) // [3]
        Array.of(3).length // 1


        //copy数组--------------------------
        //[1, 2, 3, 4, 5].copyWithin(0, 3)
        // [4, 5, 3, 4, 5]


        //查找数组成员------------------------
        //[1, 4, -5, 10].find((n) => n < 0);

        //[1, 5, 10, 15].find(function(value, index, arr) {
            //return value > 9;
        //}) //10


        //fill方法还可以接受第二个和第三个参数，用于指定填充的起始位置和结束位置。

        console.log(['a', 'b', 'c'].fill(7, 1, 2))
        // ['a', 7, 'c']

    });

    //实例新方法**********************************

    (function(){

        for (let index of Object.keys(['a', 'b'])) {
            console.log(index);
        };
        // 0
        // 1

        for (let elem of Object.values()) {
            console.log(elem);
        }
        // 'a'
        // 'b'

        for (let [index, elem] of ['a', 'b'].entries()) {
            console.log(index, elem);
        }
        // 0 "a"
        // 1 "b"

    })()




</script>
</body>
</html>






















